package com.qqtech.qquan.send.controller;

import javax.annotation.Resource;

import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.domain.Sort.Direction;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.qqtech.core.common.annotation.VisitAnnt;
import com.qqtech.core.common.enums.RespEnum;
import com.qqtech.core.frame.model.PageKit;
import com.qqtech.core.frame.model.PageOrder;
import com.qqtech.core.frame.model.Result;
import com.qqtech.core.frame.service.BaseService;
import com.qqtech.qquan.send.model.SendDeliveryOrder;
import com.qqtech.qquan.send.model.SendDeliveryOrderQuery;
import com.qqtech.qquan.send.model.SendDeliveryOrderVo;
import com.qqtech.qquan.send.model.SendDeliveryUser;
import com.qqtech.qquan.send.service.SendDeliveryOrderService;
import com.qqtech.qquan.send.service.SendDeliveryUserService;
import com.qqtech.web.context.BaseWebController;

@Controller
@RequestMapping(value = "/send/delivery/order")
public class SendDeliveryOrderController extends BaseWebController<SendDeliveryOrder, SendDeliveryOrderQuery> {
	@Resource
	private SendDeliveryOrderService sendDeliveryOrderService;
	
	@Resource
	private SendDeliveryUserService sendDeliveryUserService;
    
	@Override
	protected BaseService<SendDeliveryOrder> getBaseService() {
		return sendDeliveryOrderService;
	}
	
	/**
	 * 订单列表
	 * 
	 * @param query
	 * @return
	 */
	@VisitAnnt(type = RespEnum.LOGIN)
	@RequestMapping(value = "/page")
	@ResponseBody
	public Result page(@RequestBody SendDeliveryOrderQuery query) {
		Result result = new Result();
		if (query == null) {
			query = new SendDeliveryOrderQuery();
		}
		Page<SendDeliveryOrderVo> page = null;
		SendDeliveryUser sendDeliveryUser = sendDeliveryUserService.getByUserId(super.getUserId());
		if (sendDeliveryUser != null) {
			query.setOrderNo(query.getOrderNo());
			Pageable pageKit = new PageKit(query.getPage(), new PageOrder(
					Direction.DESC, "newAt"));
			page = sendDeliveryOrderService.queryPageList(query,
					pageKit);
		}
		result.put("page", page);
		return result;
	}
}
